Ole Objects and writing to Microsoft Word example and explanation

Is there a good reference to use to understand all the arguments for olePut, oleGet, oleMethod, etc.? I am trying to write a pretty simple script to print a log of what was done in dxl to a word document or a text file(but that seems more difficult) and between the forums, the reference manual, and browsing the web I still don't have the understanding I would like to have. I am using DOORS 9.3.

Thanks in advance,

Robert
SystemAdmin - Thu Mar 07 13:22:30 EST 2013

Re: Ole Objects and writing to Microsoft Word example and explanation
kbmurphy - Thu Mar 07 14:07:27 EST 2013

Take things one line at a time. Look at examples that work and copy them, and put a twist in.

Also, read up on Visual Basic for Applications, particularly the Word object model. If you don't know VBA, you're not going to get anywhere in OLE Automation for Word.

If you can write to a text file instead, it's WAY easier to do that, not harder. Look up Streams in the DXL reference manual.

Re: Ole Objects and writing to Microsoft Word example and explanation
llandale - Thu Mar 07 15:26:36 EST 2013

I'm struggling also.
  • olePut and oleGet deal with OleObject PROPERTIES
  • oleMethod obviously deal wth METHODS
  • put(AutoArgs) deal with PARAMETERS

Reading the MSN web site
[http://msdn.microsoft.com/en-us/library/bb214334(v=office.12).aspx]

I see the important part of these top lines:
  • expression.AddLabel(Orientation, Left, Top, Width, Height)
  • expression Required. A variable that represents a CanvasShapes collection.

Is that it deals with CanvasShapes. Your code would then look like this:
  • OleAutoObj oaoCanvas = whatever
  • OleAutoArgs oaaArgs = create
  • put(oaaArgs, "Orientation", "Left") // but Left may be an integer? Need to investigate that
  • oleMethod(oaoCanvas, "AddLabel", oaaArgs)

I see for Word I've need to be very persnikety with nuance differences between "Application", "Documents", "Document", and "Selection" Objects. My variable names therefore have "App", "Docs", "Doc", or "Sel" respectively in their names.

-Louie

Re: Ole Objects and writing to Microsoft Word example and explanation
SystemAdmin - Fri Mar 08 02:25:52 EST 2013

Hi

First rule is: Write a code snippet in VBA and if it works then transform it to dxl.

It is significant easiear to develope a vba-script inside of the excel or the word script editor and troubleshoote it there.

If it works you have to use olePut, oleGet, oleMethod to move the code to dxl.

This three routines returns an error string and so small routine will help:
 

bool checkOleErrorString(string sErrorString) {
    if (sErrorString == null) { return(false) };
        logError(sErrorString dxlHere());
        return true;
}

Inside your "vba script code" you can use:

checkOleErrorString(oleGet/Put/Method(...));


In case of an error, the error itself is logged (and it's position in the code) and using the return value, you can handle an error.

if checkOleErrorString(oleGet/Put/Method(...)) {
  // troubleshooting code
}
// standard code

 

Best regards
Wolfgang

 

 

 

 

 

 

Re: Ole Objects and writing to Microsoft Word example and explanation
SystemAdmin - Fri Mar 08 12:05:28 EST 2013

kbmurphy - Thu Mar 07 14:07:27 EST 2013
Take things one line at a time. Look at examples that work and copy them, and put a twist in.

Also, read up on Visual Basic for Applications, particularly the Word object model. If you don't know VBA, you're not going to get anywhere in OLE Automation for Word.

If you can write to a text file instead, it's WAY easier to do that, not harder. Look up Streams in the DXL reference manual.

kbmurphy,

Any advice on how to create a .txt file in the dxl script?

I see how to stream write to an already existing file but I am not sure how to create and open one for writing in dxl

---------------------{Code}-------------------------------
//stream to .txt file

//name for the .txt file
//get the date and time of the log
Date logDate = dateAndTime(today)
string logDateString = stringOf(logDate)

string outputFID = "Target Module Update Log "logDateString

//create the .txt file

//??? not sure how to do so in dxl ???

//write the results log to the .txt file
Stream logStream = write(string outputFID)

---------------------{End Code}-------------------------------

Thanks in advance,

rb24

Re: Ole Objects and writing to Microsoft Word example and explanation
kbmurphy - Fri Mar 08 13:39:38 EST 2013

SystemAdmin - Fri Mar 08 12:05:28 EST 2013
kbmurphy,

Any advice on how to create a .txt file in the dxl script?

I see how to stream write to an already existing file but I am not sure how to create and open one for writing in dxl

---------------------{Code}-------------------------------
//stream to .txt file

//name for the .txt file
//get the date and time of the log
Date logDate = dateAndTime(today)
string logDateString = stringOf(logDate)

string outputFID = "Target Module Update Log "logDateString

//create the .txt file

//??? not sure how to do so in dxl ???

//write the results log to the .txt file
Stream logStream = write(string outputFID)

---------------------{End Code}-------------------------------

Thanks in advance,

rb24

Off the top of my head:
 

Date logDate = dateAndTime(today)
string logDateString = stringOf(logDate)
 
string outputFID = "Target Module Update Log " logDateString
 
//create the .txt file
 
Steam logStream = write("c:/temp/" outputFID)
//??? not sure how to do so in dxl ???
 
outputFID << "This is the first line of the log file.\n"
outputFID << "This is the second line of the log file.\n"
 
close logStream

Re: Ole Objects and writing to Microsoft Word example and explanation
SystemAdmin - Tue Mar 12 16:47:57 EDT 2013

kbmurphy - Fri Mar 08 13:39:38 EST 2013

Off the top of my head:
 

Date logDate = dateAndTime(today)
string logDateString = stringOf(logDate)
 
string outputFID = "Target Module Update Log " logDateString
 
//create the .txt file
 
Steam logStream = write("c:/temp/" outputFID)
//??? not sure how to do so in dxl ???
 
outputFID << "This is the first line of the log file.\n"
outputFID << "This is the second line of the log file.\n"
 
close logStream

Thanks I got the stream working.

Re: Ole Objects and writing to Microsoft Word example and explanation
adevicq - Wed Mar 13 04:20:22 EDT 2013

kbmurphy - Fri Mar 08 13:39:38 EST 2013

Off the top of my head:
 

Date logDate = dateAndTime(today)
string logDateString = stringOf(logDate)
 
string outputFID = "Target Module Update Log " logDateString
 
//create the .txt file
 
Steam logStream = write("c:/temp/" outputFID)
//??? not sure how to do so in dxl ???
 
outputFID << "This is the first line of the log file.\n"
outputFID << "This is the second line of the log file.\n"
 
close logStream

Hi,
One suggestion: you can use

string sTemp = getenv("temp")


to retrieve the temp folder...
regards,